-module(nar).
-export([make_from/2]).

%% This makes an n-ar function out of function 
%% that accepts a single list as a parameter.
%% 
%% Args: F - list taking function.
%%	 Arity - of the return.
%% Returns: function of given Arity

make_from(F, Arity) ->
    Xs = string:join(["X" ++ integer_to_list(I) || I <- lists:seq(1, Arity)], ", "),
    FunStr = "fun (" ++ Xs ++ ") -> F([" ++ Xs ++ "]) end.", 
    {ok, Tokens, _} = erl_scan:string(FunStr),
    {ok, [Form]} = erl_parse:parse_exprs(Tokens),
    Bindings = erl_eval:add_binding('F', F, erl_eval:new_bindings()), 
    {value, Fa, _} = erl_eval:expr(Form, Bindings),
    Fa.